﻿using System.Collections.Generic;
using ChainAnalises.Classes.AuxiliaryClasses.WebServices.SOAP;
using ChainAnalises.Classes.IntervalAnalysis;
using ChainAnalises.Classes.Root.SimpleTypes;
using CharacteristicCalculator.Model;
using NUnit.Framework;

namespace TestCharacteristicCalculator.Model
{
    [TestFixture]
    public class TestDataTableFiller
    {
        [Test]
        public void TestCalculateCharacteristic1()
        {
            Chain Input = ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT");
            string Characteristic = "AlphabetPower";
            SoapDataCharacteristic Output = DataTableFiller.CalculateCharacteristic(Input, Characteristic,LinkUp.Both);
            Assert.AreEqual(4, Output.Value);
            Assert.AreEqual("NucleotideChainAlphabetPower", Output.Key);
        }

        [Test]
        public void TestCalculateCharacteristic2()
        {
            Chain Input = ChainGetters.GetAminoChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"));
            string Characteristic = "AlphabetPower";
            SoapDataCharacteristic Output = DataTableFiller.CalculateCharacteristic(Input, Characteristic,LinkUp.Both);
            Assert.AreEqual(5, Output.Value);
            Assert.AreEqual("AminoChainAlphabetPower", Output.Key);
        }

        [Test]
        public void TestCalculateCharacteristic3()
        {
            UniformChain Input1 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('A'));
            UniformChain Input2 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('C'));
            UniformChain Input3 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('G'));
            UniformChain Input4 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('T'));
            string Characteristic = "AlphabetPower";
            SoapDataCharacteristic Output1 = DataTableFiller.CalculateCharacteristic(Input1, Characteristic,LinkUp.Start);
            SoapDataCharacteristic Output2 = DataTableFiller.CalculateCharacteristic(Input2, Characteristic,LinkUp.Start);
            SoapDataCharacteristic Output3 = DataTableFiller.CalculateCharacteristic(Input3, Characteristic,LinkUp.Start);
            SoapDataCharacteristic Output4 = DataTableFiller.CalculateCharacteristic(Input4, Characteristic,LinkUp.Start);
            Assert.AreEqual(1, Output1.Value);
            Assert.AreEqual("AdenineChainAlphabetPower", Output1.Key);
            Assert.AreEqual(1, Output2.Value);
            Assert.AreEqual("CytozineChainAlphabetPower", Output2.Key);
            Assert.AreEqual(1, Output3.Value);
            Assert.AreEqual("GuanineChainAlphabetPower", Output3.Key);
            Assert.AreEqual(1, Output4.Value);
            Assert.AreEqual("ThymineChainAlphabetPower", Output4.Key);
        }

        [Test]
        public void TestFormDataObject()
        {
            List<ChainWithCharacteristic> chains = new List<ChainWithCharacteristic>();
            List<string> characteristics = new List<string>();
            int id = 34;
            chains.Add(ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('A')));
            chains.Add(ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('C')));
            chains.Add(ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('G')));
            chains.Add(ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"), new ValueChar('T')));
            chains.Add(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"));
            characteristics.Add("AlphabetPower");
            characteristics.Add("Length");
            SoapDataObject Output = DataTableFiller.FormDataObject(id, chains, characteristics,LinkUp.Both);
            Assert.AreEqual(34, Output.id);
            Assert.AreEqual("AdenineChainAlphabetPower", ((SoapDataCharacteristic)Output.vault[0]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)Output.vault[0]).Value);
            Assert.AreEqual("AdenineChainLength", ((SoapDataCharacteristic)Output.vault[1]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)Output.vault[1]).Value);
            Assert.AreEqual("CytozineChainAlphabetPower", ((SoapDataCharacteristic)Output.vault[2]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)Output.vault[2]).Value);
            Assert.AreEqual("CytozineChainLength", ((SoapDataCharacteristic)Output.vault[3]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)Output.vault[3]).Value);
            Assert.AreEqual("GuanineChainAlphabetPower", ((SoapDataCharacteristic)Output.vault[4]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)Output.vault[4]).Value);
            Assert.AreEqual("GuanineChainLength", ((SoapDataCharacteristic)Output.vault[5]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)Output.vault[5]).Value);
            Assert.AreEqual("ThymineChainAlphabetPower", ((SoapDataCharacteristic)Output.vault[6]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)Output.vault[6]).Value);
            Assert.AreEqual("ThymineChainLength", ((SoapDataCharacteristic)Output.vault[7]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)Output.vault[7]).Value);
            Assert.AreEqual("NucleotideChainAlphabetPower", ((SoapDataCharacteristic)Output.vault[8]).Key);
            Assert.AreEqual(4, ((SoapDataCharacteristic)Output.vault[8]).Value);
            Assert.AreEqual("NucleotideChainLength", ((SoapDataCharacteristic)Output.vault[9]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)Output.vault[9]).Value);
        }

        [Test]
        public void TestFillDataTable()
        {
            List<List<ChainWithCharacteristic>> chains = new List<List<ChainWithCharacteristic>>();
            List<int> id = new List<int>();
            List<string> characteristics = new List<string>();
            chains.Add(new List<ChainWithCharacteristic>());
            chains.Add(new List<ChainWithCharacteristic>());
            chains[0].Add(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT"));
            chains[0].Add(ChainGetters.GetAminoChain(ChainGetters.GetNucleotideChain("CCGTACTTCGTAGAT")));
            chains[1].Add(ChainGetters.GetNucleotideChain("CCGTACATCGTA"));
            chains[1].Add(ChainGetters.GetAminoChain(ChainGetters.GetNucleotideChain("CCGTACATCGTA")));
            id.Add(3);
            id.Add(5);
            characteristics.Add("Length");
            characteristics.Add("PhantomMessagesCount");
            SoapDataTable Output = DataTableFiller.FillDataTable(chains, id, characteristics,LinkUp.Both,false);
            Assert.AreEqual(2, Output.Objects.Count);
            Assert.AreEqual(3, ((SoapDataObject)Output.Objects[0]).id);
            Assert.AreEqual(5, ((SoapDataObject)Output.Objects[1]).id);
            Assert.AreEqual("NucleotideChainLength", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[0]).Key);
            Assert.AreEqual(15, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[0]).Value);
            Assert.AreEqual("NucleotideChainPhantomMessagesCount", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[1]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[1]).Value);
            Assert.AreEqual("AminoChainLength", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[2]).Key);
            Assert.AreEqual(5, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[2]).Value);
            Assert.AreEqual("AminoChainPhantomMessagesCount", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[3]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[0]).vault[3]).Value);
            Assert.AreEqual("NucleotideChainLength", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[0]).Key);
            Assert.AreEqual(12, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[0]).Value);
            Assert.AreEqual("NucleotideChainPhantomMessagesCount", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[1]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[1]).Value);
            Assert.AreEqual("AminoChainLength", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[2]).Key);
            Assert.AreEqual(4, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[2]).Value);
            Assert.AreEqual("AminoChainPhantomMessagesCount", ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[3]).Key);
            Assert.AreEqual(1, ((SoapDataCharacteristic)((SoapDataObject)Output.Objects[1]).vault[3]).Value);
        }
    }
}